package com.liuhx.mapper.sql;

import com.liuhx.entity.CityEntity;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

/**
 * Created by liuhx on 2017/6/21.
 */
public class CitySql {
    public String insertCitys(Map map)
    {
        List<CityEntity> cityEntityList = (List<CityEntity>) map.get("list");
        StringBuilder sb = new StringBuilder();
                sb.append("INSERT INTO city_info ");
                sb.append("(cityName, cityUrl) ");
                sb.append("VALUES ");
                MessageFormat mf = new MessageFormat("( #'{'list[{0}].cityName}, #'{'list[{0}].cityUrl})");
                for (int i = 0; i < cityEntityList.size(); i++) {
                    sb.append(mf.format(new Object[]{i}));
                    if (i < cityEntityList.size() - 1) {
                        sb.append(",");
                    }
                }
                return sb.toString();
    }
//    public String updateCitys(Map map)
//    {
//        List<CityEntity> cityEntityList = (List<CityEntity>) map.get("list");
//        StringBuilder sb = new StringBuilder();
//        sb.append("UPDATE SET city_info ");
//        MessageFormat mf = new MessageFormat("( #'{'list[{0}].cityName}, #'{'list[{0}].cityUrl})");
//        for (int i = 0; i < cityEntityList.size(); i++) {
//            sb.append(mf.format(new Object[]{i}));
//            if (i < cityEntityList.size() - 1) {
//                sb.append(",");
//            }
//        }
//        return sb.toString();
//    }
}
